package ihm;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import javax.swing.UIManager;

import metier.Animal;

public class FenetreModifierAnimal extends JDialog implements ActionListener
{

	private final JPanel contentPanel = new JPanel();
	private JLabel lblIdAnimal;
	private JComboBox cboTypeAnimal;
	private JLabel lblTypeAnimal;
	private JLabel lblPropreitaire;
	private JComboBox cboProprioAnimal;
	private JLabel lblNomAnimal;
	private JTextField txtNomAnimal;
	private JLabel lblDateDeNaissance;
	private JTextField txtDateDeNaissance;
	private JRadioButton rdbtnMale;
	private JRadioButton rdbtnFemelle;
	private ButtonGroup groupeSexe ;
	private JButton btnModifier;
	private JButton btnAnnuler;
	private JLabel lblId;
	private JLabel lblidAnimal;
	private int rep;
	
	private Animal unAnimal;
	private String identifiant;

	/**
	 * Create the dialog.
	 */
	public FenetreModifierAnimal(String identifiant)
	{
		this.setTitle("Ajouter un animal");
		this.setBounds(750, 370, 555, 298);
		this.getContentPane().setLayout(new BorderLayout());
		this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		this.contentPanel.setBackground(new Color(178, 200, 219));
		this.getContentPane().add(this.contentPanel, BorderLayout.CENTER);
		
		this.identifiant = identifiant;
		
		TitledBorder titreIdAnimal;
		titreIdAnimal = BorderFactory.createTitledBorder("Animal");
        addTitreId(titreIdAnimal,this.contentPanel);
        
        TitledBorder informationAnim;
		informationAnim = BorderFactory.createTitledBorder("Informations");
        addInformation(informationAnim,this.contentPanel);
		
        this.btnModifier = new JButton("Modifier");
        this.btnModifier.addActionListener(this);
        this.btnModifier.setBounds(333, 219, 85, 23);
        this.contentPanel.add(this.btnModifier);
		
        this.btnAnnuler = new JButton("Annuler");
        this.btnAnnuler.addActionListener(this);
        this.btnAnnuler.setBounds(428, 219, 80, 23);
        this.contentPanel.add(this.btnAnnuler);
		
		
	}
	public void actionPerformed(ActionEvent evt) 
	{
		if(evt.getSource()== this.btnAnnuler)
		{
			dispose();
		}
		if(evt.getSource()==this.btnModifier)
		{
			this.rep = JOptionPane.showConfirmDialog(null, "Etes vous sur de vouloir modifier l'animal ?","Message",JOptionPane.YES_NO_OPTION);

			if (this.rep == JOptionPane.YES_OPTION)
				dispose();
		}
	}
	
	void addTitreId(Border border, Container container) {
		this.contentPanel.setLayout(null);
			JPanel comp = new JPanel(false);
			comp.setBounds(35, 11, 473, 38);
			comp.setLayout(null);

			lblIdAnimal = new JLabel("ID animal :");
			comp.add(lblIdAnimal);
			lblIdAnimal.setFont(new Font("Tahoma", Font.BOLD, 12));
			lblIdAnimal.setBounds(6, 16, 89, 15);
			comp.setBorder(border);
			container.add(comp);
			
			lblidAnimal = new JLabel(this.identifiant);
			lblidAnimal.setOpaque(true);
			lblidAnimal.setBackground(Color.WHITE);
			lblidAnimal.setBounds(96, 17, 184, 14);
			comp.add(lblidAnimal);
	}
	
	void addInformation(Border border, Container container) {
		this.contentPanel.setLayout(null);
		JPanel information = new JPanel(false);
		information.setBounds(35, 60, 473, 148);
		information.setLayout(null);
		
		information.setBorder(border);
		container.add(information);
		
		lblNomAnimal = new JLabel("Nom :");
		lblNomAnimal.setBounds(10, 26, 35, 15);
		information.add(lblNomAnimal);
		lblNomAnimal.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		txtNomAnimal = new JTextField();
		txtNomAnimal.setBounds(96, 24, 185, 17);
		information.add(txtNomAnimal);
		txtNomAnimal.setColumns(10);
		
		lblPropreitaire = new JLabel("Propi\u00E9taire :");
		lblPropreitaire.setBounds(10, 93, 75, 15);
		information.add(lblPropreitaire);
		lblPropreitaire.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		cboProprioAnimal = new JComboBox();
		cboProprioAnimal.setBounds(96, 91, 185, 20);
		information.add(cboProprioAnimal);
		
		lblTypeAnimal = new JLabel("Type animal :");
		lblTypeAnimal.setBounds(10, 119, 80, 15);
		information.add(lblTypeAnimal);
		lblTypeAnimal.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		
		cboTypeAnimal = new JComboBox();
		cboTypeAnimal.setBounds(96, 117, 185, 20);
		information.add(cboTypeAnimal);
		
		lblDateDeNaissance = new JLabel("Date de naissance :");
		lblDateDeNaissance.setBounds(10, 54, 118, 15);
		information.add(lblDateDeNaissance);
		lblDateDeNaissance.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		txtDateDeNaissance = new JTextField();
		txtDateDeNaissance.setToolTipText("jj/mm/aaaa");
		txtDateDeNaissance.setBounds(139, 52, 142, 20);
		information.add(txtDateDeNaissance);
		txtDateDeNaissance.setColumns(10);
        
		TitledBorder sexeAnim;
        sexeAnim = BorderFactory.createTitledBorder("Sexe");
        addsexeAnim(sexeAnim,information);
		
	}
	
	void addsexeAnim(Border border, Container container) {
		contentPanel.setLayout(null);
		JPanel sexe = new JPanel(false);
		sexe.setBounds(319, 26, 144, 74);
		sexe.setLayout(null);
		
		sexe.setBorder(border);
		container.add(sexe);
		groupeSexe = new ButtonGroup();
		
		rdbtnFemelle = new JRadioButton("Femelle");
		rdbtnFemelle.setBounds(17, 44, 69, 23);
		sexe.add(rdbtnFemelle);
		rdbtnFemelle.setFont(new Font("Tahoma", Font.BOLD, 12));
		rdbtnFemelle.setBackground(UIManager.getColor("Button.background"));
		groupeSexe.add(this.rdbtnFemelle);
		
		rdbtnMale = new JRadioButton("M\u00E2le");
		rdbtnMale.setBounds(17, 18, 53, 23);
		sexe.add(rdbtnMale);
		rdbtnMale.setFont(new Font("Tahoma", Font.BOLD, 12));
		rdbtnMale.setBackground(UIManager.getColor("Button.background"));
		groupeSexe.add(this.rdbtnMale);
	}
}
